/** 
 * @description: 优化代码量
 * @fileName: index.js 
 * @author: 袁室祥 
 * @date: 2022-07-05 20:25:07
 * @后台人员:  
 */
function cardType(type) {
    //判断是哪种类型卡片
    switch (type) {
        case '白卡武将':
            let whiteRandom = parseInt(Math.random() * whiteCard.length)
            return whiteCard[whiteRandom].url
            break;
        case '蓝卡武将':
            let blueRandom = parseInt(Math.random() * blueCard.length)
            return blueCard[blueRandom].url
            break;
        case '绿卡武将':
            let greenRandom = parseInt(Math.random() * greenCard.length)
            return greenCard[greenRandom].url
            break;
        case '紫卡武将':
            let purpleRandom = parseInt(Math.random() * purpleCard.length)
            return purpleCard[purpleRandom].url
            break;
        case '橙卡武将':
            let orangeRandom = parseInt(Math.random() * orangeCard.length)
            return orangeCard[orangeRandom].url
            break;
    }
}

function cardStyle(cardString, spanDom, borderDom, classList, addUrl) { //调用处理卡片url、class方法
    let url = cardType(cardString)
    cardUrl(spanDom, url)
    cardCalss(borderDom, classList, addUrl)

}

function cardUrl(dom, url) {
    //统一处理展示的url
    // 给元素添加url
    dom.style.backgroundImage = `url(${url})`
}

function cardCalss(dom, delUrlList, addUrl) {
    //统一处理展示的calss
    dom.classList.remove(...delUrlList); //要删除的class
    dom.classList.add(addUrl); //要添加的class

}

function reset() {
    //重置卡牌
    for (let i = 0; i < dom.length; i++) {
        dom[i].style.transition = 'all 0s';
        if (conArr.length === dom.length) {

            dom[i].style.transform = 'rotateY(' + 360 + 'deg)';
            p[i].style.display = 'block'
            span[i].style.display = 'none'
            border[i].style.display = 'none'
            span[i].style.color = '#fff'
        }
        if (conArr.indexOf(i) == -1) {
            p[i].removeAttribute('index')

            dom[i].style.transform = 'rotateY(' + 360 + 'deg)';
            p[i].style.display = 'block'
            span[i].style.display = 'none'
            border[i].style.display = 'none'
            span[i].style.color = '#fff'
        }

    }

}